package com.app.shop.controller.system;

import com.app.shop.util.ApiRest;
import com.app.shop.util.Constant;
import com.app.shop.util.DictModel;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 字典服务类Controller
 *
 * @author  chen li wei
 * @version 21:14 2019-5-10
 */
@Controller
@RequestMapping(value = "/dict")
public class DictController extends BaseController {

    /**
     * 查询相关字典值
     * @param jsonObject
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(value = "/getDictListByStudent")
    public ApiRest getDictList(@RequestBody JSONObject jsonObject)
            throws IOException {

        //必须输入获取字典编码
        if (jsonObject == null) {
            return new ApiRest(Constant.REST_ERROR_CODE, Constant.ERROR_MESSAGE);
        }
        Map<String,List<DictModel>> dicMap=new HashMap<String, List<DictModel>>();
        //获取全部字典
        for (Integer integer :Constant.DIC_MAP.keySet()) {
            dicMap.put("dict"+integer,Constant.DIC_MAP.get(integer));
        }

        Map map=new HashMap();
        map.put("dict",dicMap);

        return new ApiRest(Constant.REST_SUCCESS_CODE, Constant.SUCCESS_MESSAGE,map);
    }

}
